package com.qianli.cashmama.product.facade.enums;

import org.apache.commons.lang3.StringUtils;

import java.util.concurrent.ConcurrentHashMap;

/**
 * Created by xuyang on 2017/7/19.
 */
public enum RuleOwnerTypeEnum {
    PRODUCT("PRODUCT", "Product"),                                  // 产品
    PRODUCT_CATEGORY("PRODUCT_CATEGORY", "Product category");       // 产品类目

    private String code;

    private String name;

    RuleOwnerTypeEnum(String code, String name) {
        this.code = code;
        this.name = name;
    }

    public String getCode() {
        return code;
    }

    public String getName() {
        return name;
    }

    public static RuleOwnerTypeEnum getByCode(String code) {
        if (StringUtils.isEmpty(code)) {
            return null;
        }
        code = code.toUpperCase();
        return RuleOwnerTypeMapper.map.get(code);
    }

    private static class RuleOwnerTypeMapper {
        private static ConcurrentHashMap<String, RuleOwnerTypeEnum> map = new ConcurrentHashMap<>();

        static {
            for (RuleOwnerTypeEnum ownerType : RuleOwnerTypeEnum.values()) {
                map.put(ownerType.code, ownerType);
            }
        }
    }
}
